﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Dimok.Shared {
  public partial class ReportProfile {
		public const string EXCEL_REPORT_KEY = "ExcelReportKey";
		public const string EXCEL_REPORT_URL = "ExcelFromCache.aspx";
		public const string EXCEL_REPORT_NAME = "application/vnd.ms-excel";
		public string ReportName { get; set; }
		public string[] ReportNames { get; set; }
		public Dictionary<string, string> Filters { get; set; }
    public Dictionary<string, ListSortDirection> Sorts { get; set; }
    public string[] Columns { get; set; }
		public string Docks { get; set; }
		public bool? ShowFilter { get; set; }
		public bool? ShowTotals { get; set; }
		public bool? ShowAverages { get; set; }
    public MetaTablesDictionary MetaTables { get; set; }
		public ReportProfile() { }
		public ReportProfile(string reportName) {
			ReportName = reportName;
		}
	}

  public partial class MetaTablesDictionary : Dictionary<string, Dictionary<string, MetaField>> {
    public void Add<TEntity>(Dictionary<string, MetaField> metaFields) {
      Add(typeof(TEntity).Name, metaFields);
    }
  }
  public partial class MetaFieldsDictionary : Dictionary<string, MetaField> {
    public static  MetaFieldsDictionary Factory<TEntity>(){
      return new MetaFieldsDictionary(typeof(TEntity));
    }
    Type entityType;
    public MetaFieldsDictionary() { }
    public MetaFieldsDictionary(Type entityType) { this.entityType = entityType; }
    public new void Add(string propertyName, MetaField metaField) {
      if (entityType!=null && entityType.GetProperty(propertyName) == null)
        throw new MissingMemberException("Property " + propertyName + " does not exist in " + entityType.FullName + ".");
      base.Add(propertyName, metaField);
    }
  }

  public class MetaField {
		string _formatString;
		public string FormatString {
			get { return _formatString; }
			set { 
				_formatString = value;
				if (FormatStringAvg == null) FormatStringAvg = value;
			}
		}
		private string _formatStringAvg;
		public string FormatStringAvg {
			get { return _formatStringAvg; }
			set { 
				_formatStringAvg = value;
				if (value!=null && FormatStringSum == null) FormatStringSum = value;
			}
		}
		string _formatStringSum;
		public string FormatStringSum {
			get { return _formatStringSum; }
			set { 
				_formatStringSum = value;
				if (value != null && FormatStringAvg == null) FormatStringAvg = value;
			}
		}
    public bool IsTotal { get; set; }
    public bool IsAverage { get; set; }
    public byte DisplayIndex { get; set; }
		public bool IsEnum { get; set; }
	}

  public enum ListSortDirection {
    Ascending = 0,
    Descending = 1,
  }

}
